import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:熟练掌握各种运算符
 * User: 阿宾
 * Date: 2024-05-01
 * Time: 22:06
 */
public class Test01 {
    public static void main(String[] args) {
        byte a = 65; //0100 0001
        System.out.printf("%d\n",a << 1);//130
        System.out.printf("%d\n",a);//65
    }
    public static void main12(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个数字：");
        int a = scanner.nextInt();
        System.out.println("请输入另一个数字：");
        int b = scanner.nextInt();
        System.out.println(a == 6 || b == 6 ||(a + b) % 6 == 0);
    }
    public static void main11(String[] args) {
        int a = 10;
        int b = 10;
        boolean result = ++a < 5 & ++b < 5;
        System.out.println(result);
        System.out.println(a);
        System.out.println(b);
    }
    public static void main10(String[] args) {
        int a = 10;
        int b = 20;
        //表达式结果是boolean类型时，表示逻辑运算
        System.out.println(a > b);
        System.out.println(a < b);
        //& |不能执行短路运算,&& ||可以执行
        System.out.println(a > b && 10/0 == 0);//如果发生短路运算，则只会执行表达式1，结果是false
        System.out.println(a < b || 10/0 == 0);//如果发生短路运算，则只会执行表达式1，结果是true

        /*System.out.println(a > b & 10/0 == 0);//如果发生短路运算，则只会执行表达式1，结果是false
        System.out.println(a < b | 10/0 == 0);//如果发生短路运算，则只会执行表达式1，结果是true*/
    }
    public static void main9(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入第一个数字：");
        int a = scanner.nextInt();
        System.out.println("请输入第二个数字：");
        int b = scanner.nextInt();
        System.out.println(a > b);
    }
    public static void main8(String[] args) {
        int a = 10;
        int b = a++;
        System.out.println(a);//11
        System.out.println(b);//10

        int a2 = 10;
        int b2 = ++a2;
        System.out.println(a2);//11
        System.out.println(b2);//11
    }
    public static void main7(String[] args) {
        char a = 'a';
        System.out.println(a);
        System.out.println(a + "字符串");
        System.out.println(a + 1);
    }
    public static void main6(String[] args) {
        System.out.println(1.1+1.01);
        System.out.println(1.1+1.1);
        System.out.println(10.0 / 3);
        System.out.println(10 / 3);
        Scanner scanner = new Scanner(System.in);
        /*System.out.println("请输入三位数：");
        int sc = scanner.nextInt();
        System.out.println(sc % 10);
        System.out.println(sc / 10 % 10);
        System.out.println(sc / 100 % 10);*/
        System.out.println(11.5 % 2);
    }
    public static void main1(String[] args) {
        System.out.println(5/2);//2
        System.out.println((float)5/2);//2.5 先把5强转为5.0，然后进行除法
        System.out.println(5/(float)2);//2.5
        System.out.println((float)(5/2));//2.0
        //-----------------
        System.out.println(10%3);//1
        System.out.println(10%-3);//1
        System.out.println(-10%3);//-1 求模结果的正负号由第一个运算数的正负号决定
        System.out.println(-10%-3);//-1
        //java中可以对小数求余数
        System.out.println(11.5%2);//1.5
        System.out.println(-11.5%2);//-1.5
        System.out.println(9.0 % 3);//0.0，如果操作数中存在小数，则求余结果为小数，否则结果是整数
        System.out.println(9 % 3);//0


    }

    public static void main2(String[] args) {
        int a = 1;
        int b = 0;
        //System.out.println(a/b);
        long a1 = 100L;
        int a2 = 200;
        //a2 = a1+a2;//error,因为等式右边计算后是long类型，与左边不同
        a2 += a1;//没有报错，因为运算符会实现类型转换
        System.out.println(a2);//300
    }

    /*public static void main(String[] args) {
        //获取一个数的每一位
        //1.键盘录入一个三位数
        //导包 --- 创建对象 --- 接收数据
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个三位数:");
        int number = sc.nextInt();//123
        //2.获取这个三位数的个位、十位、百位并打印出来
        int ge = number % 10;
        int shi = number / 10 % 10;
        int bai = number / 100 % 10;
        System.out.println(ge);
        System.out.println(shi);
        System.out.println(bai);
    }*/
    /*public static void main(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println(a | b);
        System.out.println(a | a);
    }*/
   /* public static void main(String[] args) {
        //按位运算
        System.out.println(10 > 20 & 10 / 0 == 0);
        System.out.println(10 < 20 | 10 / 0 == 0);
    }*/

    public static void main13(String[] args) {
        int a = 1;
        int b = 2;
        System.out.println(a == 1 && b == 2); // 左为真 且 右为真 则结果为真
        System.out.println(a == 1 && b > 100); // 左为真 但 右为假 则结果为假
        System.out.println(a > 100 && b == 2); // 左为假 但 右为真 则结果为假
        System.out.println(a > 100 && b > 100); // 左为假 且 右为假 则结果为假
    }

    public static void main3(String[] args) {
        int a = 1;
        //System.out.println(!a);//error
        System.out.println(!(a==1));
        System.out.println(!(a==2));
    }

    public static void main4(String[] args) {
        //短路求值
        //短路与 当表达式1为假时，就不会执行表达式2
//        System.out.println(10 > 20 && 10 / 0 == 0);
//        //短路或 当表达式1为真时，就不会执行表达式2
//        System.out.println(10 < 20 || 10 / 0 == 0);

        System.out.println(10 > 20 & 10 / 0 == 0); // 程序抛出异常
        System.out.println(10 < 20 | 10 / 0 == 0); // 程序抛出异常
    }

    public static void main5(String[] args) {
        int a = 0xf;
        System.out.printf("%x\n",a);//f
        System.out.printf("%d\n",a);//15
        /*
        因为a占4字节，所以内存中是00000000 00000000 00000000 00001111
        然后按位取反，得11111111 11111111 11111111 11110000 十六进制是ff ff ff f0
        转为原码是10000000 00000000 00000000 00010000 => -16
         */

        System.out.printf("%x\n",~a);//fffffff0
        System.out.printf("%d\n",~a);//-16

        int a1 = 1;
        int b1 = 2;
        double c1 = a1 > b1? a1 : 2.0;
        //int c2 = a1 > b1? a1 : 2.0;// error 因为2.0是double,不能隐式转换到int类型
        System.out.println(c1);
    }


}
